package com.kingtsoft.study.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kingtsoft.study.common.JsonResult;
import com.kingtsoft.study.constant.DescribableEnum;
import com.kingtsoft.study.core.PageRequest;
import com.kingtsoft.study.model.StudyHomework;
import com.kingtsoft.study.model.StudyHomeworkDetail;
import com.kingtsoft.study.service.StudyHomeworkCheckService;
import com.kingtsoft.study.service.StudyHomeworkDetailService;
import com.kingtsoft.study.util.PageUtil;

@Controller
@RequestMapping("study/homeworkCheck")
public class StudyHomeworkCheckController {

	@Autowired
	StudyHomeworkCheckService homeworkCheckService;

	@Autowired
	StudyHomeworkDetailService homeworkDetailService;

	/**
	 * 
	 * @Title: checkPage
	 * @Description: TODO
	 * @param homeworkId
	 * @return
	 * @return: ModelAndView
	 */
	@RequestMapping(value = "/page/check")
	public ModelAndView checkPage(String homeworkId) {
		ModelAndView mav = new ModelAndView("/homework/homework_checklist");
		mav.addObject("homeworkId", homeworkId);
		return mav;

	}

	/**
	 * 
	 * @Title: check
	 * @Description: 查看作业
	 * @param homeworkId
	 * @author jxh
	 * @return: JsonResult
	 */
	@RequestMapping(value = "/checklist")
	@ResponseBody
	public JsonResult check(PageRequest pageRequest, String homeworkId) {
		PageInfo page = PageUtil.getPage(pageRequest);
		PageHelper.startPage(page);
		List<StudyHomeworkDetail> list = homeworkCheckService.check(homeworkId);
		// 用PageInfo对结果进行包装
		PageInfo pageInfo = new PageInfo(list);
		JsonResult jsonResult = new JsonResult(DescribableEnum.SUCCESS, pageInfo);
		return jsonResult;
	}

	@RequestMapping(value = "/page/checkdetail")
	public ModelAndView checkdetail(String homeworkDetailId) {
		ModelAndView mav = new ModelAndView("/homework/homework_checkdetail");
		StudyHomeworkDetail homeworkDetail = homeworkDetailService.load(homeworkDetailId);
		mav.addObject("homeworkDetail", homeworkDetail);
		return mav;
	}
}
